<template>
  <div id="index">
    <el-container class="box">
      <el-aside width="230px">
        <el-row class="tac">
          <el-col :span="12" style="width: 100%">
            <el-menu
              default-active="1-1"
              class="el-menu-vertical-demo"
              background-color="#ff6141"
              text-color="#fff"
              active-text-color="#ffd04b"
              unique-opened
              router
            >
              <el-menu-item index="/">
                <i class="el-icon-location"></i>
                <span slot="title">首页</span>
              </el-menu-item>
              <div v-for="item in user.menus" :key="item.id">
                <el-submenu index="item.id+''" v-if="item.children">
                  <template slot="title">
                    <i class="item.icon"></i>
                    <span>{{ item.title }}</span>
                  </template>
                  <el-menu-item
                    :index="i.url"
                    v-for="i in item.children"
                    :key="i.id"
                    >{{ i.title }}</el-menu-item
                  >
                </el-submenu>
                <el-submenu index="item.id+''" v-else>{{ item.title }}</el-submenu>
              </div>
            </el-menu>
          </el-col>
        </el-row>
      </el-aside>
      <el-container>
        <el-header
          >后台管理系统
          <el-button type="danger" @click="Goout">退出登录</el-button>
        </el-header>
        <el-main>
          <el-breadcrumb separator="/">
            <el-breadcrumb-item :to="{ path: '/' }">首页</el-breadcrumb-item>
            <el-breadcrumb-item>{{ $route.meta.title }}</el-breadcrumb-item>
          </el-breadcrumb>
          <router-view></router-view>
        </el-main>
      </el-container>
    </el-container>
  </div>
</template>
<script>
import { mapActions } from "vuex";
import { successAlert } from "../../util/alert.js";
import store from "../../store/index";
export default {
  data() {
    return {
      user: [],
    };
  },
  methods: {
    handleOpen(key, keyPath) {
      console.log(key, keyPath);
    },
    handleClose(key, keyPath) {
      console.log(key, keyPath);
    },
    ...mapActions({
      reqChangeUser: "reqChangeUser",
    }),
    Goout() {
      this.reqChangeUser({});
      successAlert("退出成功");
      this.$router.push("/login");
    },
  },
  mounted() {
    this.user = store.state.user;
    console.log(this.user);
  },
};
</script>

<style lang="less" scoped>
@import url("../../less/index.less");
.box {
  width: 100vw;
  height: 100vh;
}
.el-header {
  background-color: @color1;
  color: #333;
  color: #fff;
  font-size: 30px;
}

.el-aside {
  background-color: @color1;
  color: #333;
}

.el-main {
  background-color: #e9eef3;
  color: #333;
}
</style>